//
// Created by Joy on 2024/7/29.
//

#include <bits/stdc++.h>
#define N 15
using namespace std;

int BinarySearch(int *a,int target){
    int left = 0,right = N - 1;
    while (left <= right){
        int n = (left+right)/2;
        if (a[n] < target){
            left = n + 1;
        } else if(a[n] > target){
            right = n - 1;
        } else if(a[n] == target){
            return n;
        }
    }
    return -1;
}
int sort (int *a){
    for (int i = 0; i < N - 1; ++i) {
        int k = i;
        for (int j = i + 1; j < N; ++j) {
            if (a[k] > a[j]){
                k = j;
            }
        }
        swap(a[i],a[k]);
    }
}

int main() {

    int arr[N] = {6,3,17,100,0,12,8,7,20,78,30,-3,38,66,1};
    sort(arr);
    for (int i = 0; i < N; ++i) {
        cout <<i<<":"<< arr[i] << " ";
    }
    cout << "\n------------------------------------"<< endl;
    int result = BinarySearch(arr,100);
    cout << result;
    return 0;
}
